// 公共头部
Vue.component('header-bar', {
    template: "<div style='border:none;height:60px;line-height:58px;color:white;font-family:宋体;font-size:12px'>"
        + "<div id='navbar' style='margin-left:20px'>"
        + "<div style='float:left;'>"
        + "<img :src='imgSrc' alt='简睿捷' style='width:10%;'></img>"
        + "<span style='font-family:幼圆;font-size:26px;color:white;margin-left:15px;font-weight:bold'>MES认知</span>"
        + "<span style='font-family:宋体;font-size:18px;color:white;margin-left:8%;font-weight:bold'>{{pagename}}</span>"
        + "</div>"
        + "<div>"
        + "<img class='brand-img' :src='userSrc' alt='简睿捷' style='height:25px;width:25px;margin-top:15px'>"
        + " <el-dropdown><span class='el-dropdown-link' style='color:white'>"
        + "{{userinfo.user.properties.name}}<i class='el-icon-arrow-down el-icon--right'></i></span>"
        + "<el-dropdown-menu slot='dropdown'>"
        + "<el-dropdown-item @click.native='logOut'>退出</el-dropdown-item> "
        + "<el-dropdown-item @click.native='goPersonCenter'>个人中心</el-dropdown-item></el-dropdown-menu></el-dropdown>"
        + "<i class='el-icon-location' style='border-left:solid 1px white;padding-left:20px;margin:auto 10px;'  @click.native='goMain'></i><span style='cursor:pointer'>首页</span>"
        + "</div>"
        + "</div>"
        + "<scroll-up></scroll-up>"
        + "</div>",
    data: function () {
        return {
            path: '',
            userSrc: '',
            imgSrc: '',
            showMain: true
        }
    },
    props: ['pagename', 'userinfo'],
    methods: {
        //    回首页
        goMain: function () {
            window.location.href = this.path + '/mes_school/addorder.html';
        },
        // 登出
        logOut: function () {
            window.location.href = this.path + '/mes_school/login.html';
        },
        // 进个人中心
        goPersonCenter: function () {
            window.location.href = this.path + '/mes_school/personCenter.html';
        }
    },
    created: function () {
        this.path = getRootPath();
        window.location.href.indexOf('/report/') >= 0 ? this.showMain = false : this.showMain = true;
        this.userSrc = getRootPath() + "/mes_school/img/user.png";
        this.imgSrc = getRootPath() + "/mes_school/img/logo.png"
    },
    mounted: function () {

    }
});

//公共侧面导航
Vue.component('side-bar', {
    template: "<el-row style='color:white;font-family:宋体;font-size:15px;margin-top:15px' >"
        + "<el-row v-for='(menu,index) in menus' @click.native='active(menu,index)'>"
        + "<el-row  v-if='index==0' :class='{menuActive:selectedPagename==menu.name}' class='menu'><el-col :offset='3' :span='3'><i class='el-icon-menu'></i></el-col><el-col :span='18'>{{menu.name}}</el-col></el-row>"
        + "<el-row v-if='index!==0&&index!==6&&index!==7' :class='{menuActive:selectedPagename==menu.name}' class='menu'><el-col :offset='6' :span='18'>{{menu.name}}</el-col></el-row>"
        + "<el-row v-if='index==6' :class='{menuActive:selectedPagename==menu.name}' class='menu'><el-col :offset='3' :span='3'><i class='el-icon-picture'></i></el-col><el-col :span='18'>{{menu.name}}</el-col></el-row>"
        + "<el-row v-if='index==7' :class='{menuActive:selectedPagename==menu.name}' class='menu'><el-col :offset='3' :span='3'><i class='el-icon-service'></i></el-col><el-col :span='18'>{{menu.name}}</el-col></el-row>"
        + "</el-row> "
        + "<img  :src='bgSrc'  style='width:14%;position:fixed;bottom:0px;margin-top:15px'>"
        + "</el-row>",
    data: function () {
        return {
            path: '',
            bgSrc: '',
            showMain: true,
            menus: [
                { name: "MES" },
                { name: "订单管理", url: "addorder.html" },
                { name: "计划排产", url: "teamPlan.html" },
                { name: "生产派工", url: "claimWork.html" },
                { name: "生产报工", url: "reportWork.html" },
                { name: "生产质检", url: "inspection.html" },
                { name: "综合报表", url: "reportnav.html" },
                { name: "我的任务", url: "myWork.html" },
            ],
            selectedPagename: "",

        }
    },
    props: ['pagename', 'userinfo'],
    methods: {
        active: function (menu, index) {
            window.location.href = this.path + "/mes_school/" + menu.url;
        }
    },
    watch: {
        pagename(val) {
            this.selectedPagename = val;
        }
    },
    created: function () {
        this.path = getRootPath();
        window.location.href.indexOf('/report/') >= 0 ? this.showMain = false : this.showMain = true;
        this.bgSrc = this.path + "/mes_school/img/sidebarBg.png";
        this.selectedPagename = document.getElementsByTagName("TITLE")[0].text;
    },
    mounted: function () {

    }
});

// 开工，报工，我的任务详细信息弹出框
Vue.component('detailmsg', {
    template: "<el-dialog title='计划详细信息' :visible.sync='Dialog' class='md_dialog_700 md_dialog_min_700'>"
        + "<el-form :inline='true' v-if='tempItem' id='detailMsgID' class='self_form self_formLabel_100 center'>"
        + "<el-col :xs='24' :sm='12' :md='12' :lg='12'>"
        + "<el-form-item label='生产工序'>"
        + "<el-input v-model='tempItem.properties.qcpprocess.processname' :readonly='true'></el-input>"
        + "</el-form-item>"
        + "</el-col>"
        + "<el-col :xs='24' :sm='12' :md='12' :lg='12'>"
        + "<el-form-item label='产品代号'>"
        + "<el-input v-model='tempItem.properties.mesproductionschedule.productno' :readonly='true'></el-input>"
        + "</el-form-item>"
        + "</el-col>"
        + "<el-col :xs='24' :sm='12' :md='12' :lg='12'>"
        + "<el-form-item label='物料号'>"
        + "<el-input v-model='tempItem.properties.mesproductionschedule.materialno' :readonly='true'></el-input>"
        + "</el-form-item>"
        + "</el-col>"
        + "<el-col :xs='24' :sm='12' :md='12' :lg='12'>"
        + "<el-form-item label='产品名称'>"
        + "<el-input v-model='tempItem.properties.mesproductionschedule.name' :readonly='true'></el-input>"
        + "</el-form-item>"
        + "</el-col>"
        + "<el-col :xs='24' :sm='12' :md='12' :lg='12'>"
        + "<el-form-item label='批次号'>"
        + "<el-input v-model='tempItem.properties.mesproductionschedule.lotno' :readonly='true'></el-input>"
        + "</el-form-item>"
        + "</el-col>"
        + "<el-col :xs='24' :sm='12' :md='12' :lg='12'>"
        + "<el-form-item label='批次数量'>"
        + "<el-input v-model='tempItem.properties.mesproductionschedule.lotnum' :readonly='true'></el-input>"
        + "</el-form-item>"
        + "</el-col>"
        + "<el-col :xs='24' :sm='12' :md='12' :lg='12'>"
        + "<el-form-item label='计划开工时间'>"
        + "<el-input v-model='tempItem.properties.mesproductionschedule.startdate' :readonly='true'></el-input>"
        + "</el-form-item>"
        + "</el-col>"
        + "<el-col :xs='24' :sm='12' :md='12' :lg='12'>"
        + "<el-form-item label='计划完工时间'>"
        + "<el-input v-model='tempItem.properties.mesproductionschedule.enddate' :readonly='true'></el-input>"
        + "</el-form-item>"
        + "</el-col>"
        + "<el-col :xs='24' :sm='12' :md='12' :lg='12'>"
        + "<el-form-item label='操作人'>"
        + "<el-input v-model='userinfo.user.properties.name' :readonly='true'></el-input>"
        + "</el-form-item>"
        + "</el-col>"
        + "<el-col :xs='24' :sm='12' :md='12' :lg='12'>"
        + "<el-form-item label='操作时间'>"
        + "<el-input v-model='currentTime' :readonly='true'></el-input>"
        + "</el-form-item>"
        + "</el-col>"
        + "</el-form>"
        + "<div id='schedule_detailMsg' style='display:none'>"
        + "<table>"
        + "    <tr>"
        + "        <td><div>生产工序</div></td>"
        + "        <td><div>{{tempItem.properties.qcpprocess.processname}}</div></td>"
        + "        <td><div>产品代号</div></td>"
        + "        <td><div>{{tempItem.properties.mesproductionschedule.productno}}</div></td>"
        + "    <tr>"
        + "    <tr>"
        + "        <td><div>物料号</div></td>"
        + "        <td><div>{{tempItem.properties.mesproductionschedule.materialno}}</div></td>"
        + "        <td><div>产品名称</div></td>"
        + "        <td><div>{{tempItem.properties.mesproductionschedule.name}}</div></td>"
        + "    <tr>"
        + "    <tr>"
        + "        <td><div>批次号</div></td>"
        + "        <td><div>{{tempItem.properties.mesproductionschedule.lotno}}</div></td>"
        + "        <td><div>批次数量</div></td>"
        + "        <td><div>{{tempItem.properties.mesproductionschedule.lotnum}}</div></td>"
        + "    <tr>"
        + "    <tr>"
        + "        <td><div>计划开工时间</div></td>"
        + "        <td><div>{{tempItem.properties.mesproductionschedule.startdate}}</div></td>"
        + "        <td><div>计划完工时间</div></td>"
        + "        <td><div>{{tempItem.properties.mesproductionschedule.enddate}}</div></td>"
        + "    <tr>"
        + "    <tr>"
        + "        <td><div>操作人</div></td>"
        + "        <td><div>{{userinfo.user.properties.name}}</div></td>"
        + "        <td><div>操作时间</div></td>"
        + "        <td><div>{{currentTime}}</div></td>"
        + "    <tr>"
        + "</table>"
        + "</div>"
        + "<el-row style='text-align:center'>"
        + "<el-button type='primary' plain @click='printView(\"schedule_detailMsg\")'>打印</el-button>"
        + "<el-button plain @click='Dialog = false'>关闭</el-button>"
        + "</el-row>"
        + "</el-dialog>"
    ,
    data: function () {
        return {
            Dialog: false,
            currentTime: '',
            tempItem: null
        }
    },
    props: ['differentdialogitem', 'userinfo'],
    methods: {

    },
    created: function () {
        var self = this;
        this.Dialog = true;
        this.tempItem = this.differentdialogitem;
        this.currenttime = '';
        // 获取当前时间
        vm.common_fn.getCurrentTime(function (time) {
            self.currentTime = time;
        })
    },
    mounted: function () {

    },
    destroyed: function () {
        this.Dialog = false;
        this.tempItem = null;
    }
});

// 人员选择器（多选）
Vue.component('people-sel-mul', {
    template: "<el-dialog title='人员选择' :visible.sync='personDialog' id='peopleSelComponent'>"
        + "<el-row>"
        + "<el-input placeholder='人员搜索' icon='search' v-model='search' @change='searchclick()'></el-input>"
        + "</el-row>"
        + "<el-row>"
        + "<div class='people_sel_left'>"
        + "<ul class='peoplelist'>"
        + "<li v-for='(list,index) in searchpeoplelist' @click='selpeople(list)'>{{list.properties.name}}</li>"
        + "</ul>"
        + "</div>"
        + "<div class='people_sel_right'>"
        + "<ul>"
        + "<li v-for='(list,index) in sel'>{{list.properties.name}}"
        + "<i class='el-icon-circle-close' @click='del(list,index)'></i>"
        + "</li>"
        + "</ul>"
        + "</div>"
        + "</el-row>"
        + "<span slot='footer' class='dialog-footer'>"
        + "<el-button type='primary' @click='select'>确 定</el-button>"
        + "</span>"
        + "</el-dialog>",
    data: function () {
        return {
            personDialog: false,
            search: '',
            searchpeoplelist: [],
            allPeopleList: [],
            sel: []
        }
    },
    props: ['userinfo', 'obj'],
    // 输入obj必须是如下格式
    // obj:{
    //     targetdataname:'data',//目标数组
    //     index:0,//第几个
    //     key:''//哪个字段
    //     str:'张三,李四'//以逗号隔开的人员字符串
    // }
    methods: {
        // 搜索
        searchclick: function () {
            if (this.search == '') {
                this.searchpeoplelist = this.allPeopleList; return
            }
            this.searchpeoplelist = [];
            for (var i = 0; i < this.allPeopleList.length; i++) {
                if (this.allPeopleList[i].properties.name.indexOf(this.search) > -1) {
                    this.searchpeoplelist.push(this.allPeopleList[i]);
                }
            }
        },
        // 选择人员
        selpeople: function (row) {
            var self = this;
            for (var i = 0; i < self.sel.length; i++) {
                if (row.id == self.sel[i].id) { return }
            }
            self.sel.push(row);
        },
        del: function (row, index) {
            this.sel.splice(index, 1);
        },
        //确认退出
        select: function () {
            var self = this;
            bus.$emit('retselpeople', { result: self.sel, target: self.obj });
            self.personDialog = false;
        }
    },
    mounted: function () {
        var self = this;
        queryObject("SysPerson", [], self.userinfo.user, function (response) {
            if (response.resFlag == 0) {
                self.allPeopleList = response.result;
                self.searchpeoplelist = response.result;
                self.personDialog = true;
                //将之前选择的列出来
                var val = self.obj.str;
                if (val != '') {
                    var arr = val.split(',');
                    for (var i = 0; i < arr.length; i++) {
                        for (var j = 0; j < self.allPeopleList.length; j++) {
                            if (arr[i] == self.allPeopleList[j].properties.name) {
                                self.sel.push(self.allPeopleList[j]);
                            }
                        }
                    }
                }
            } else {
                self.$notify.error({
                    title: '错误',
                    message: response.errMsg
                });
            }
        })
    },
    destroyed: function () {
        this.sel = [];
    }
});
// 人员选择器（单选）
Vue.component('people-sel', {
    template: "<el-dialog title='人员选择' :visible.sync='personDialog' id='peopleSelComponent'>"
        + "<el-row>"
        + "<el-input placeholder='人员搜索' icon='search' v-model='search' @change='searchclick()'></el-input>"
        + "</el-row>"
        + "<el-row>"
        + "<div>"
        + "<ul class='peoplelist'>"
        + "<li v-for='(list,index) in searchpeoplelist' @click='selpeople(list)'>{{list.properties.name}}</li>"
        + "</ul>"
        + "</div>"
        + "</el-row>"
        + "</el-dialog>",
    data: function () {
        return {
            personDialog: false,
            search: '',
            searchpeoplelist: [],
            allPeopleList: []
        }
    },
    props: ['userinfo', 'obj'],
    // 输入obj必须是如下格式
    // obj:{
    //     targetdataname:'data',//目标数组
    //     index:0,//第几个
    //     key:''//哪个字段
    // }
    methods: {
        // 搜索
        searchclick: function () {
            if (this.search == '') {
                this.searchpeoplelist = this.allPeopleList; return
            }
            this.searchpeoplelist = [];
            for (var i = 0; i < this.allPeopleList.length; i++) {
                if (this.allPeopleList[i].properties.name.indexOf(this.search) > -1) {
                    this.searchpeoplelist.push(this.allPeopleList[i]);
                }
            }
        },
        // 选择人员
        selpeople: function (row) {
            var self = this;
            bus.$emit('retonepeople', { result: row, target: self.obj });
            self.personDialog = false;
        }
    },
    mounted: function () {
        var self = this;
        queryObject("SysPerson", [], self.userinfo.user, function (response) {
            if (response.resFlag == 0) {
                self.allPeopleList = response.result;
                self.searchpeoplelist = response.result;
                self.personDialog = true;
            } else {
                self.$notify.error({
                    title: '错误',
                    message: response.errMsg
                });
            }
        })
    },
    destroyed: function () {
        this.personDialog = false;
    }
});
// 人员选择器（报工页面专用）
Vue.component('report-people-sel', {
    template: "<el-dialog title='人员选择' :visible.sync='personDialog' id='reportPeopleSel' class='md_dialog_600 md_dialog_min_300' append-to-body>"
        + "<el-row>"
        + "    <el-col :span='12'>"
        + "        <el-col :span='24'>当前班组人员</el-col>"
        + "        <el-col :span='24' style='text-align:center'>"
        + "          <ul style='list-style: none;padding-left: 0;margin: 0 15px'>"
        + "              <li v-for='list in teamuser'  @click='selpeople(list)' style='padding: 5px 0 5px 10px;margin:8px 0;border-radius: 5px;cursor: pointer' onmouseover='this.style.backgroundColor=\"#e8e8e8\"' onmouseout='this.style.backgroundColor=\"#fff\"'><span>{{list.properties.name}}</span></li>"
        + "          </ul>"
        + "        </el-col>"
        + "    </el-col>"
        + "    <el-col :span='12'>"
        + "        <el-col :span='24'>所有人员</el-col>"
        + "        <el-col :span='24' style='text-align:center'>"
        + "                    <ul v-for='(value,key) in peopleobj' style='list-style: none;padding-left: 0;margin: 0'>"
        + "                        <li id='{{key}}' style='padding:5px 0 5px 2px;background-color: #cccccc;border-radius: 5px'><span style='margin-left: 10px'>{{key}}</span></li>"
        + "                        <li v-for='list in value' @click='selpeople(list)' style='padding: 5px 0 5px 10px;margin:5px 0;border-radius: 5px' onmouseover='this.style.backgroundColor=\"#e8e8e8\"' onmouseout='this.style.backgroundColor=\"#fff\"'>{{list.properties.name}}</li>"
        + "                    </ul>"
        + "            </el-col>"
        + "    </el-col>"
        + "</el-row>"
        + "</el-dialog>",
    data: function () {
        return {
            personDialog: false,
            search: '',
            searchpeoplelist: [],
            allPeopleList: [],
            teamuser: [],
            peopleobj: {}
        }
    },
    props: ['differentdialogitem', 'userinfo'],
    methods: {
        init: function () {
            this.peopleobj = this.differentdialogitem.peopleDictionary;
            this.teamuser = this.differentdialogitem.teamuser;
            debugger
        },
        // 搜索
        searchclick: function () {
            if (this.search == '') {
                this.searchpeoplelist = this.allPeopleList; return
            }
            this.searchpeoplelist = [];
            for (var i = 0; i < this.allPeopleList.length; i++) {
                if (this.allPeopleList[i].properties.name.indexOf(this.search) > -1) {
                    this.searchpeoplelist.push(this.allPeopleList[i]);
                }
            }
        },
        // 选择人员
        selpeople: function (row) {
            var self = this;
            bus.$emit('retonepeople', { result: row, target: self.differentdialogitem.index });
            self.personDialog = false;
        }
    },
    created: function () {
        this.personDialog = true;
        this.init();
    },
    mounted: function () {
        var self = this;
    },
    destroyed: function () {
        this.personDialog = false;
    }
});

// 查看图纸
Vue.component('view-doc', {
    template: "<el-dialog title='文件列表' :visible.sync='Dialog' class='md_dialog_600'>"
        + "<el-card class='box-card' v-for='list in files' style='margin-bottom:5px'>"
        + "<a v-bind:href='list.properties.doc_url' target='_blank'>{{list.properties.name}}</a>"
        + "</el-card>"
        + "<el-row style='text-align:center'>"
        + "<el-button plain @click='Dialog = false'>关闭</el-button>"
        + "</el-row>"
        + "</el-dialog>"
    ,
    data: function () {
        return {
            Dialog: false,
            files: []
        }
    },
    props: ['differentdialogitem', 'userinfo'],
    methods: {
        viewdoc: function (identityno) {
            var self = this;
            self.files = [];
            var param = {
                type: "SysDocumentRev",
                filters: [
                    {
                        "classFlag": 0,
                        "classType": "SysDocumentRev",
                        "propName": "name",
                        "op": 7,
                        "propValue": identityno,  //图号
                        "propValue2": null,
                        "logic": 1,
                        "leftSplitter": 0,
                        "rightSplitter": 0,
                        "bAddWhereClauseFlag": true
                    }
                ],
                pageIndex: 1,
                pageNum: 1000,
                user: self.userinfo.user
            };
            self.go_docpreview(param);
        },
        go_docpreview: function (param) {
            var self = this;
            vm.common_fn.XHR_post('../app/invoke?fun=QueryPagingObject', param, function (response) {
                if (response.resFlag == 0) {
                    if (response.result.length == 0) {
                        notify_timeOut('没有相关图纸', 'error')
                    } else {
                        self.files = response.result;
                        for (var a = 0; a < self.files.length; a++) {

                            if (self.files[a].properties.name.toLocaleLowerCase().indexOf('pdf') == -1) {
                                self.files[a].properties['doc_url'] = '../file/DownFile?docid=' + self.files[a].id;
                            } else {
                                self.files[a].properties['doc_url'] = '../pdfviewer/web/viewer.html?docids=' + self.files[a].id;
                            }
                        }
                        self.Dialog = true;
                    }
                } else {
                    notify(response.errMsg, 'error')
                }
            })

        }
    },
    created: function () {
        this.viewdoc(this.differentdialogitem);
    },
    mounted: function () {

    },
    destroyed: function () {
        this.Dialog = false;
        this.files = [];
    }
});
// 主页消息通知
Vue.component('sysmessage', {
    template: "<div id='sysMessage' v-show='msg>0 || unreadtask>0'>"
        + "<div id='sysMessage_msg' v-show='msg>0'><span>{{msg}}</span>&nbsp条未读消息</div>"
        + "<div id='sysMessage_task' v-show='unreadtask>0'><span>{{unreadtask}}</span>&nbsp条未读流程任务</div>"
        + "</div>",
    data: function () {
        return {
            msg: 0,
            unreadtask: 0,

        }
    },
    props: ['differentdialogitem', 'userinfo'],
    methods: {

    },
    created: function () {

    },
    mounted: function () {
        this.msg = this.differentdialogitem.split('_')[0];
        this.unreadtask = this.differentdialogitem.split('_')[1];
        window.setInterval(function () {

        }, 800)
    }
});


// 回到顶部
Vue.component('scroll-up', {
    template: "<div id='btn_to_top' style='position:fixed;right:20px;bottom:20px;display:none;z-index:9999'>" +
        "<el-button size='large' icon='el-icon-arrow-up' @click='toTop()' style='background:#ff5722;color:#fff;border-color:transparent'></el-button>" +
        "<el-button size='large' style='position:absolute;left:-115px;top:10px;background:#ff5722;color:#fff;border-color:transparent;display:none'>回到顶部</el-button>" +
        "</div>",
    data: function () {
        return {

        }
    },
    props: [],
    methods: {
        toTop: function () {
            $('html,body').animate({ scrollTop: 0 }, 400)
        }
    },
    created: function () {

    },
    mounted: function () {
        $(window).scroll(function () {
            if ($(window).scrollTop() >= 300) {
                $('#btn_to_top').fadeIn(500);
            }
            if ($(window).scrollTop() < 270) {
                $('#btn_to_top').fadeOut(500);
            }
        })
        $('#btn_to_top button:first-child').hover(function () {
            $('#btn_to_top button:nth-child(2)').fadeIn(300);
        }, function () {
            $('#btn_to_top button:nth-child(2)').fadeOut(300);
        })
    }
});
